import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;

class Student implements Comparable<Student>{   // 2.定义类时，实现Comparable接口，然后在类中重写ComparaTo方法
    public String name;
    public int age;
    public Student(){

    };
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // 1.覆写基类的equals
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }


    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}


// 3. 基于比较器比较
class NameComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}

class AgeComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}

class Incmp implements Comparator<Integer>{


    @Override
    public int compare(Integer o1, Integer o2) {
        // return o2 - o1;
        return o2.compareTo(o1);
    }
}

public class Test2 {
    public static void main(String[] args) {
        Student student1 = new Student("张三",21);
        Student student2 = new Student("张三",11);
        System.out.println(student1 == student2);
        System.out.println(student1.equals(student2));
        System.out.println(student1.compareTo(student2));

        NameComparator nameComparator = new NameComparator();
        System.out.println(nameComparator.compare(student1, student2));

        Incmp inCmp = new Incmp();
        Queue<Integer> priorityQueue = new PriorityQueue<>(inCmp);
        priorityQueue.offer(1);
        priorityQueue.offer(2);
        System.out.println("aaaaaaaaaa");

    }

}
